package flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : DuJiabao
 * @Date : 2021/3/3 23:00
 * @Project : design-pattern
 * @File : null.java
 * @Desc :
 */
public class ChessPieceUnitFactory {
  private static final Map<Integer, ChessPieceUnit> pieces = new HashMap<>(); // 存储所有棋子的一个仓库

  static {
    pieces.put(1, new ChessPieceUnit(1, "車", ChessPieceUnit.Color.BLACK));
    pieces.put(2, new ChessPieceUnit(2, "馬", ChessPieceUnit.Color.BLACK));
    //...省略摆放其他棋子的代码...
  }

  /**
   * 根据ID获取棋子
   * @param chessPieceId
   * @return
   */
  public static ChessPieceUnit getChessPiece(int chessPieceId) {
    return pieces.get(chessPieceId);
  }
}
